package com.fenxiangle.yueding.feature.home.view.adapter;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.fenxiangle.yueding.R;
import com.fenxiangle.yueding.entity.TransactionType;
import com.fenxiangle.yueding.entity.bo.TranscctionBo;

import java.util.List;

/**
 * Created by luoxw on 2016/8/9.
 */
public class ExpandableYJAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    private static final String TAG = ExpandableYJAdapter.class.getSimpleName();

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;

    public ExpandableYJAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_expandable_lv1);
        addItemType(TYPE_LEVEL_1, R.layout.item_expandable_lv0);
    }


    @Override
    protected void convert(final BaseViewHolder holder, final MultiItemEntity item) {
        switch (holder.getItemViewType()) {
            case TYPE_LEVEL_0:
                final TranscctionBo lv0 = (TranscctionBo) item;
                holder.setText(R.id.title, lv0.getCreateTime())
                        .setGone(R.id.first_money, false);
                ImageView iv=holder.getView(R.id.iv);
                if(lv0.isExpanded()){
                    iv.animate().setDuration(500).rotation(0).start();
                }else{
                    iv.animate().setDuration(500).rotation(180).start();
                }
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getAdapterPosition();
                        Log.d(TAG, "Level 0 item pos: " + pos);
                        if (lv0.isExpanded()) {
                            collapse(pos);
                        } else {
//                            if (pos % 3 == 0) {
//                                expandAll(pos, false);
//                            } else {
                            expand(pos);
//                            }
                        }
                    }
                });
                break;
            case TYPE_LEVEL_1:
                final TranscctionBo.CommissionFormMapBean lv1 = (TranscctionBo.CommissionFormMapBean) item;
                holder.setText(R.id.iv_title, ((TranscctionBo.CommissionFormMapBean) item).getMsg())
                        .setText(R.id.iv_money, lv1.getTransactionMount()+"元")
                        .setText(R.id.iv_time, lv1.getCreateTime());
                break;
        }
    }
}
